/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.dao;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;

import com.thinkgem.jeesite.common.persistence.BaseDao;
import com.thinkgem.jeesite.common.persistence.BaseDaoImpl;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.boxin.ims.modules.wechat.entity.WechatMember;

/**
 * 微信会员DAO接口
 * @author Jakemanse
 * @version 2013-09-08
 */
public interface WechatMemberDao extends WechatMemberDaoCustom, CrudRepository<WechatMember, Long> {

	@Modifying
	@Query("update WechatMember set delFlag='" + WechatMember.DEL_FLAG_DELETE + "' where  id = ?1  ")
	public int deleteById(Long id);
	
	@Modifying 
	@Query("update WechatMember set name=?1 where  id = ?2  ")
	public int modifyName(String name,Long id);
	
	@Modifying 
	@Query("update WechatMember set mobile=?1 where  id = ?2  ")
	public int modifyMobile(String mobile,Long id);
	
	@Modifying
	@Query("delete from  WechatMember   where  id = ?1  ")
	public int removeById(Long id);
	
	
	@Modifying
	@Query("delete from  WechatMember  where   user.id = ?1  and wechatId = ?2")
	public int deleteByUserIdAndWechatId(Long UserId,String wechatOpenId);
	

	@Query(" from  WechatMember  where   user.id = ?1  and wechatId = ?2")
	public WechatMember getByUserIdAndOpenId(Long userId,String openId);
	
	@Modifying 
	@Query("update WechatMember set recommendScore=recommendScore+?1 where  id = ?2  ")
	public int addRecommendScoreById(Integer recommendScore,Long id);
	
	/**
	 * @author Jakemanse
	 * @time 2014-3-31  下午11:51:52
	 * @function <p> 修改成生会员卡号 </p>
	 * @param memberId
	 */
//	@Modifying
//	@Query("update  WechatMember set number = = CONCAT ('MBR', LPAD(?1,10,'0'))  where   id = ?1")
//	public void updateWechatMemberCardNumber(Long memberId); 
	
	
	@Query(" from  WechatMember  where   user.id = ?1  and wechatId = ?2")
	public WechatMember getByWechatMemberId(Long userId,String wechatId);
	
	
	
	@Query(" from  WechatMember  where   user.id = ?1  and number = ?2")
	public WechatMember getByUserIdAndNumber(Long userId,String number);
	
	
	@Query(" from  WechatMember  where   number = ?1")
	public WechatMember getByNumber(String number);
	
	
	
	@Query(" from  WechatMember  where   recommendCode = ?1")
	public WechatMember getByRecommandCode(String recommendCode);
	
	@Query(" from  WechatMember  where   sceneId = ?1")
	public WechatMember getBySceneId(String sceneId);
	
	@Query(" from  WechatMember  where   jiuSceneId = ?1")
	public WechatMember getByJiuSceneId(String jiuSceneId);
	
	@Query(" from  WechatMember  where   jiuFinanceSceneId = ?1")
	public WechatMember getByFinanceSceneId(String jiuFinanceSceneId);
	
	@Query(" from  WechatMember  where   wechatId = ?1")
	public WechatMember getByWechatId(String wechatId);
	
}

/**
 * DAO自定义接口
 * @author Jakemanse
 */
interface WechatMemberDaoCustom extends BaseDao<WechatMember> {

}

/**
 * DAO自定义接口实现
 * @author Jakemanse
 */
@Component
class WechatMemberDaoImpl extends BaseDaoImpl<WechatMember> implements WechatMemberDaoCustom {

}
